﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Autodesk.AutoCAD.Interop;
using Autodesk.AutoCAD.Interop.Common;
using Autodesk.AutoCAD.Geometry;
using Autodesk.AutoCAD.DatabaseServices;
using Utilities;
using System.IO;
using System.Runtime.InteropServices;
using System.Globalization;
namespace mycad
{
    public partial class Form1 : Form
    {
        Autodesk.AutoCAD.Interop.AcadApplication AcadApp;
        Autodesk.AutoCAD.Interop.AcadDocument AcadDoc;
        string[][] fenstr;
        int[,] zuobiao;
        IniFile myini;
        IniFile tempini;
        int intset;
        int l ;                    //绘图时列坐标数组的列序号
        int h ;                    //绘图时行坐标数组的行序号
        int hcount ;               //绘图时已经绘制的行数
        public Form1()
        {
            InitializeComponent();
            fenstr = new string[1024][];
            fenstr[0] = new string[] { "0" };
            intset = 0;
        }
//启动CAD
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                AcadApp = (AcadApplication)System.Runtime.InteropServices.Marshal.GetActiveObject("AutoCAD.Application");
                AcadDoc = AcadApp.ActiveDocument;
            }
            catch
            {
                OpenFileDialog POpenDG = new OpenFileDialog();
                POpenDG.ShowDialog();
                string filePath = POpenDG.FileName;
                AcadApp = new AcadApplication();
                AcadDoc = AcadApp.Documents.Open(filePath, null, null);
            }
            AcadApp.Application.Visible = true;
            Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption);
        }

//读取section节中的键值
        private void read_kgl(string section)
        {
            int sum;
            string str;
            char[] ch = new char[] { ' ' };

            sum = myini.GetInt16(section, "SUM", 0);
            string s = sum.ToString();

            fenstr[0][0] = s;
            for (int i = 1; i <= sum; i++)
            {
                str = myini.GetString(section, i.ToString(), "error");
                if (str.CompareTo("error") == 0)
                {
                    MessageBox.Show("读key名称错误");
                    return;
                }
                fenstr[i] = str.Split(ch, StringSplitOptions.RemoveEmptyEntries);
            }

        }
//读取表格坐标kgl
        private void read_zuobiao()
        {
            read_kgl("坐标");
            int n1 =int.Parse(fenstr[0][0]);
            zuobiao = new int[n1,16];
          //  zuobiao[]=new int[16];
          //  int n2=fenstr[].Length;
            for(int i = 1; i <= n1; i++)
            {
                for (int j = 0; j < fenstr[i].Length; j++)
                {
                    zuobiao[i - 1,j] = int.Parse(fenstr[i][j]);
                }
            }
        }
//读取表格坐标mnl后面参数m没有意义，就是为了区分kgl进行重载
        //private void read_zuobiao(int m)
        //{
        //    read_kgl("坐标");
        //    int n1 = int.Parse(fenstr[0][0]);
        //    zuobiao = new int[n1, 16];
        //    //  zuobiao[]=new int[16];
        //    //  int n2=fenstr[].Length;
        //    for (int i = 1; i <= n1; i++)
        //    {
        //        for (int j = 0; j < fenstr[i].Length; j++)
        //        {
        //            zuobiao[i - 1, j] = int.Parse(fenstr[i][j]);
        //        }
        //    }
        //}
 //打开对应的INI文件
        private void button2_Click(object sender, EventArgs e)
        {
            string filename;
            Stream myStream = null;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = System.Environment.CurrentDirectory;
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|ini files(*.ini)|*.ini|All files (*.*)|*.*";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    if ((myStream = openFileDialog1.OpenFile()) != null)
                    {
                        using (myStream)
                        {
                            // Insert code to read the stream here.
                        }
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
                }
                filename = openFileDialog1.FileName;
                myini = new IniFile(filename);
                tempini = new IniFile(filename);
                
            }

          
        }
//写CAD信号机道岔信息
        private void button3_Click(object sender, EventArgs e)
        {
            int l=0, h=0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount=-1;
            read_zuobiao();
            read_kgl("信号机道岔");
            int count = int.Parse(fenstr[0][0]);
            int n=0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf=tempini.GetString("分线盘","内分","error");
            if(nf.CompareTo("error")==0)
                return;
            while(n++<count)
            {
                int n1 = fenstr[n].Length;
                if (n1 > 1)
                {
                    if (fenstr[n][1].IndexOf('D') == 0)
                    {
                        xh[++xhcount] = fenstr[n][1] + "A-B";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-14";
                        xh[++xhcount] = fenstr[n][1] + "-B";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-15";

                    }
                    else if(fenstr[n][1].CompareTo("0")!=0)
                    {
                        xh[++xhcount] = fenstr[n][1] + "LA-L";
                        xhpeixian[xhcount] = nf +  fenstr[n][0] + "-13";
                        xh[++xhcount] = fenstr[n][1] + "DA-B";
                        xhpeixian[xhcount] = nf +  fenstr[n][0] + "-14";
                        xh[++xhcount] = fenstr[n][1] + "-L";
                        xhpeixian[xhcount] = nf +  fenstr[n][0] + "-16";
                        xh[++xhcount] = fenstr[n][1] + "-B";
                        xhpeixian[xhcount] = nf +  fenstr[n][0] + "-15";

                    }
                }
                if (n1 > 2)
                {
                    if (fenstr[n][2].CompareTo("0") != 0)
                    {
                        xh[++xhcount] = fenstr[n][2] + "DB-L";
                        xhpeixian[xhcount] = nf +  fenstr[n][0] + "-7";
                        xh[++xhcount] = fenstr[n][2] + "FB-U";
                        xhpeixian[xhcount] = nf +  fenstr[n][0] + "-8";
                    }
                }
                if (n1 > 3)
                {
                    if (fenstr[n][3].CompareTo("0") != 0)
                    {
                        xh[++xhcount] = fenstr[n][3] + "-H";
                        xhpeixian[xhcount] = nf +  fenstr[n][0] + "-2";
                        xh[++xhcount] = fenstr[n][3] + "-B";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-1";
                    }
                }
                int tempn=-1;
              
                while (++tempn <= xhcount)
                {
                   
                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }   
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h]-hcount*160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h+1]-hcount*160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;
               
            }
        }
//往CAD写文字
        private void AddText(double[] p, string textString,int height)
        {
            Microsoft.VisualBasic.Interaction.AppActivate(AcadApp.Caption);
            AcadDoc.ModelSpace.AddText(textString, p, height);
        }
//写CAD进站信号机信息
        private void button4_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("进站信号机");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("分线盘", "内分", "error");
            if (nf.CompareTo("error") == 0)
                return;
            while (n++ < count)
            {
                int n1 = fenstr[n].Length;
                if (n1 > 1)
                {
                        xh[++xhcount] = fenstr[n][1] + "YZSA-B";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-2";
                        xh[++xhcount] = fenstr[n][1] + "JG-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-3";
                        xh[++xhcount] = fenstr[n][1] + "TA-L";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-5";                  
                        xh[++xhcount] = fenstr[n][1] + "YA-B";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-7";
                        xh[++xhcount] = fenstr[n][1] + "WG-H";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-9";
                        xh[++xhcount] = fenstr[n][1] + "WG-B";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-10";
                        xh[++xhcount] = fenstr[n][1] + "LA-L";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-13";
                        xh[++xhcount] = fenstr[n][1] + "-L";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-16";
                        xh[++xhcount] = fenstr[n][1] + "-H";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-18";
                        xh[++xhcount] = fenstr[n][1] + "-B";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-17";

                   
                }
                if (n1 > 2)
                {
                    
                    if (fenstr[n][2].LastIndexOf('A') == fenstr[n][2].Length-1)
                    {
                        xh[++xhcount] = fenstr[n][2] + "-B";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-14";
                       
                    }
                    else
                    {
                        xh[++xhcount] = fenstr[n][2] + "-B";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-15";
                        xh[++xhcount] = fenstr[n][2] + "A-B";
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-14";
                    }
                }
               
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
 //写电源1信息
        private void button5_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("电源1");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("分线盘", "内分", "error");
            if (nf.CompareTo("error") == 0)
                return;
            while (n++ < count)
            {
                
                    xh[++xhcount] = fenstr[n][1] + "DR-H";
                    xhpeixian[xhcount] = nf  + fenstr[n][0] + "-1";
                    xh[++xhcount] = fenstr[n][1] + "LR-H";
                    xhpeixian[xhcount] = nf  + fenstr[n][0] + "-2";
                    xh[++xhcount] = "JC-H";
                    xhpeixian[xhcount] = nf  + fenstr[n][0] + "-6";
                  
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写电源2信息
        private void button6_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("电源2");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("分线盘", "内分", "error");
            if (nf.CompareTo("error") == 0)
                return;
            while (n++ < count)
            {

                xh[++xhcount] = fenstr[n][1] + "DR-H";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-1";
                xh[++xhcount] = fenstr[n][1] + "LR-H";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-2";
               
                xh[++xhcount] = "副电源-U";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-7";
                xh[++xhcount] = "主电源-L";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-8";
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写方向信息
        private void button7_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("方向");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("分线盘", "内分", "error");
            if (nf.CompareTo("error") == 0)
                return;
            while (n++ < count)
            {

                xh[++xhcount] = fenstr[n][1] + "ZR-H";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-4";
                xh[++xhcount] = fenstr[n][1] + "ZQ-H";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-6";
                xh[++xhcount] = fenstr[n][1] + "PL-H";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-7";
                xh[++xhcount] = fenstr[n][1] + "ZD-L";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-9";
                xh[++xhcount] = fenstr[n][1] + "ZF-U";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-11";
                xh[++xhcount] = fenstr[n][1] + "LJJ";
                xhpeixian[xhcount] = fenstr[n][1] + "LJJ83";
                xh[++xhcount] = fenstr[n][1] + "LFJ";
                xhpeixian[xhcount] = fenstr[n][1] + "LFJ83";
                xh[++xhcount] = fenstr[n][1] + "DJJ";
                xhpeixian[xhcount] = fenstr[n][1] + "DJJ83";
                xh[++xhcount] = fenstr[n][1] + "DFJ";
                xhpeixian[xhcount] = fenstr[n][1] + "DFJ83";


              
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写零散信息
        private void button8_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("零散");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("分线盘", "内分", "error");
            if (nf.CompareTo("error") == 0)
                return;
            while (n++ < count)
            {
                int n1 = fenstr[n].Length;
                int n2;
                n2=0;
                while (++n2 < n1)
                {
                    if (fenstr[n][n2].CompareTo("0") != 0)
                    {
                        xh[++xhcount] = fenstr[n][n2];
                        xhpeixian[xhcount] = nf  + fenstr[n][0] + "-" + n2.ToString();
                    }
                }
                
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写站内移频信息开关量(FBJ)
        private void button9_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            //string[] mnl = new string[18];
            //string[] ss1=new string[18];
            //string[] ss2 = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("站内移频");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string namestr = tempini.GetString("站内移频", "名称", "error");
            if (namestr.CompareTo("error") == 0)
                return;
            char[] ch = new char[] { ' ' };
            string[] name = namestr.Split(ch, StringSplitOptions.RemoveEmptyEntries);
           
            while (n++ < count)
            {   //对于站内或者区间柜，用来区分ZY1 YP1还是 ZY2 YP2 
                //if(n<=int.Parse(name[2]))
                //{
                //    nf=name[0]+name[1];
                //}
                //else
                //{
                //    nf=name[0]+name[3];
                //}

                int n1 = fenstr[n].Length;
                if (n1 > 3)
                {
                    xh[++xhcount] = fenstr[n][0] + "FBJ";
                    xhpeixian[xhcount] = fenstr[n][4] + fenstr[n][5];
                }
                //if (n1 > 5)
                //{
                //    if (fenstr[n][2].CompareTo("0") != 0)
                //    {
                       
                //    }
                //}
                //if (n1 > 7)
                //{
                   
                //}
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 14)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写区间移频开关量信息(JBJ)
        private void button10_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            //string[] mnl = new string[18];
            //string[] ss1=new string[18];
            //string[] ss2 = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("区间移频");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("区间移频", "名称", "error");
            if (nf.CompareTo("error") == 0)
                return;
           
            while (n++ < count)
            {   //对于站内或者区间柜，用来区分ZY1 YP1还是 ZY2 YP2 
                int n1 = fenstr[n].Length;
                if (n1 > 2)
                {
                    xh[++xhcount] = fenstr[n][0] + "JBJ";
                    xhpeixian[xhcount] = nf +fenstr[n][1]+ "-"+ fenstr[n][2]+"02-4";
                }
                //if (n1 > 5)
                //{
                //    if (fenstr[n][2].CompareTo("0") != 0)
                //    {

                //    }
                //}
                //if (n1 > 7)
                //{

                //}
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 14)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写QZ开关量
        private void button11_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian = new string[100];
            //string[] mnl = new string[18];
            //string[] ss1=new string[18];
            //string[] ss2 = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("QZ");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
        
            while (n++ < count)
            {   
                int n1 = fenstr[n].Length;
                int n2;
                n2 = 0;
                while (++n2 < n1)
                {
                    if (fenstr[n][n2].CompareTo("0") != 0)
                    {
                        xh[++xhcount] = fenstr[n][n2] + "-L";
                        xhpeixian[xhcount] =fenstr[n][0] + "-" + n2.ToString() +"07-3";
                        xh[++xhcount] = fenstr[n][n2] + "-H";
                        xhpeixian[xhcount] = fenstr[n][0] + "-" + n2.ToString() + "07-4";
                        xh[++xhcount] = fenstr[n][n2] + "-U";
                        xhpeixian[xhcount] = fenstr[n][0] + "-" + n2.ToString() + "07-2";
                        xh[++xhcount] = fenstr[n][n2] + "FBJ";
                        xhpeixian[xhcount] = fenstr[n][0] + "-" + n2.ToString() + "07-10";
                        xh[++xhcount] = fenstr[n][n2] + "G-H";
                        xhpeixian[xhcount] = fenstr[n][0] + "-" + n2.ToString() + "07-9";

                    }
                }
            
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 14)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写QZH
        private void button12_Click(object sender, EventArgs e)
        {
            int l = 0;//, h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian1 = new string[100];
            string[] xhpeixian2 = new string[100];

            int xhcount = -1;
            read_zuobiao();
            read_kgl("QZH");

            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {
                int n1 = 0;

                while (++n1 < fenstr[n].Length)
                {
                    if (fenstr[n][n1].CompareTo("0") != 0)
                    {
                        xh[++xhcount] = fenstr[n][n1] + "发送电缆侧电压";
                        xhpeixian1[xhcount] = fenstr[n][0] + "-" + (4*(n1-1)+1).ToString();
                        xhpeixian2[xhcount] = fenstr[n][0] + "-" + (4*(n1-1)+3).ToString();
                        xh[++xhcount] = fenstr[n][n1] + "接收电缆侧电压";
                        xhpeixian1[xhcount] = fenstr[n][0] + "-" + (4 * (n1-1)+2).ToString();
                        xhpeixian2[xhcount] = fenstr[n][0] + "-" + (4 * (n1-1)+4).ToString();
                    }
                }
                n1 = 0;
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 7)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                        hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[2, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian1[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l + 1];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian2[tempn], 3);
                    l++;
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写站内移频的模拟量
        private void button13_Click(object sender, EventArgs e)
        {
            int l = 0;// h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian1 = new string[100];
            string[] xhpeixian2 = new string[100];
          
            int xhcount = -1;
            read_zuobiao();
            read_kgl("站内移频");
            string nf=tempini.GetString("站内移频","名称","error");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {  
                int n1 = fenstr[n].Length;
               
                if( n1>5)
                {
                    if (int.Parse(fenstr[n][3]) == 2)
                    {
                        xh[++xhcount] = fenstr[n][0]+"-1FS";
                        xhpeixian1[xhcount] = nf + fenstr[n][1] + "-" + fenstr[n][2] + "02-1";
                        xhpeixian2[xhcount] = nf + fenstr[n][1] + "-" + fenstr[n][2] + "02-2";
                        xh[++xhcount] = fenstr[n][0] + "-2FS";
                        xhpeixian1[xhcount] = nf + fenstr[n][1] + "-" + fenstr[n][2] + "03-1";
                        xhpeixian2[xhcount] = nf + fenstr[n][1] + "-" + fenstr[n][2] + "03-2";

                        xh[++xhcount] = fenstr[n][0] + "-1FS电流";
                        xhpeixian1[xhcount] = "FBJ31";
                        xhpeixian2[xhcount] = fenstr[n][4] +  fenstr[n][7];
                        xh[++xhcount] = fenstr[n][0] + "-2FS电流";
                        xhpeixian1[xhcount] = "FBJ51";
                        xhpeixian2[xhcount] = fenstr[n][4] +  fenstr[n][9];
                    }
                    else
                    {
                        xh[++xhcount] = fenstr[n][0] + "-FS";
                        xhpeixian1[xhcount] = nf + fenstr[n][1] + "-" + fenstr[n][2] + "02-1";
                        xhpeixian2[xhcount] = nf + fenstr[n][1] + "-" + fenstr[n][2] + "02-2";
                        if (n1 > 7)
                        {
                            xh[++xhcount] = fenstr[n][0] + "-FS电流";
                            xhpeixian1[xhcount] = "FBJ31";
                            xhpeixian2[xhcount] = fenstr[n][4] + fenstr[n][7];
                        }
                    }
                }

                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 7)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                            hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[2, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2*l];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian1[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2*l+1];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian2[tempn], 3);
                    l++;
                }
                tempn = -1;
                xhcount = -1;

            }

        }
//写区间移频的模拟量
        private void button14_Click(object sender, EventArgs e)
        {
            int l = 0;// h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian1 = new string[100];
            string[] xhpeixian2 = new string[100];

            int xhcount = -1;
            read_zuobiao();
            read_kgl("区间移频");
            string nf = tempini.GetString("区间移频", "名称", "error");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {
                int n1 = fenstr[n].Length;

                if (n1 > 2)
                {
                    
                        xh[++xhcount] = fenstr[n][0] + "功出";
                        xhpeixian1[xhcount] = nf + fenstr[n][1] + "-" + fenstr[n][2] + "02-1";
                        xhpeixian2[xhcount] = nf + fenstr[n][1] + "-" + fenstr[n][2] + "02-2";
                       
                   
                }

                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 7)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                        hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[2, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian1[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l + 1];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian2[tempn], 3);
                    l++;
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写QZ的模拟量
        private void button15_Click(object sender, EventArgs e)
        {
            int l = 0;// h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian1 = new string[100];
            string[] xhpeixian2 = new string[100];

            int xhcount = -1;
            read_zuobiao();
            read_kgl("QZ");
          
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {
                int n1 = 0;

                while (++n1 < fenstr[n].Length)
                {
                    if (fenstr[n][n1].CompareTo("0") != 0)
                    {
                        xh[++xhcount] = fenstr[n][n1] + "轨入";
                        xhpeixian1[xhcount] = fenstr[n][0] + "-" + n1.ToString() + "02-11";
                        xhpeixian2[xhcount] = fenstr[n][0] + "-" + n1.ToString() + "02-12";
                    }
                }
                n1 = 0;
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 7)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                        hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[2, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian1[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l + 1];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian2[tempn], 3);
                    l++;
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写CA 
        private void button16_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("道岔");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
           
            while (n++ < count)
            {
                int n1 = fenstr[n].Length;
               
                if (n1 > 1)
                {
                        xh[++xhcount] = fenstr[n][0] + "CA-H";
                        xhpeixian[xhcount] =fenstr[n][1] + "05-9";
                }
               
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写道岔ini
        private void button17_Click(object sender, EventArgs e)
        {
            int n = 0;
            read_kgl("信号机道岔");
            tempini.WriteValue("道岔", "SUM", 0);
            for (int i = 0; i <= int.Parse(fenstr[0][0]); i++)
            {
                if (fenstr[i].Length > 2 && fenstr[i][2].CompareTo("0")!=0)
                {
                    tempini.WriteValue("道岔", (++n).ToString(), fenstr[i][2]);
                }
            }
            tempini.WriteValue("道岔", "SUM", n);
            MessageBox.Show("ok");
        }
//写轨道ini
        private void button18_Click(object sender, EventArgs e)
        {
            int n = 0;
            read_kgl("信号机道岔");
            tempini.WriteValue("轨道", "SUM", 0);
            for (int i = 0; i <=int.Parse(fenstr[0][0]); i++)
            {
                if (fenstr[i].Length > 3 && fenstr[i][3].CompareTo("0") != 0)
                {
                    tempini.WriteValue("轨道", (++n).ToString(), fenstr[i][3]);
                }
            }
            tempini.WriteValue("轨道", "SUM", n);
            MessageBox.Show("ok");
        }
//写信号机INI
        private void button19_Click(object sender, EventArgs e)
        {
            int n = 0;
            read_kgl("信号机道岔");
            tempini.WriteValue("信号机", "SUM", 0);
            for (int i = 0; i <= int.Parse(fenstr[0][0]); i++)
            {
                if (fenstr[i].Length > 1 && fenstr[i][1].CompareTo("0") != 0 && fenstr[i][1].IndexOf("D")!=0)
                {
                    tempini.WriteValue("信号机", (++n).ToString(), fenstr[i][1]);
                }
            }
            read_kgl("进站信号机");
            for (int i = 0; i <= int.Parse(fenstr[0][0]); i++)
            {
                if (fenstr[i].Length > 1 )
                {
                    tempini.WriteValue("信号机", (++n).ToString(), fenstr[i][1]);
                }
            }
            tempini.WriteValue("信号机", "SUM", n);
            MessageBox.Show("ok");
        }
//写人解按钮
        private void button20_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("轨道");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {
                int n1 = fenstr[n].Length;

                if (n1 > 0)
                {
                    xh[++xhcount] = fenstr[n][0] + "SGA";
                   // xhpeixian[xhcount] = fenstr[n][1] + "05-9";
                }

                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    //AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写轨道电压
        private void button21_Click(object sender, EventArgs e)
        {
            int l = 0;// h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian1 = new string[100];
            string[] xhpeixian2 = new string[100];

            int xhcount = -1;
            read_zuobiao();
            read_kgl("轨道电压");
            
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {
                int n1 = fenstr[n].Length;

                if (n1 > 2)
                {

                    xh[++xhcount] = fenstr[n][0] + "电压";
                    xhpeixian1[xhcount] =fenstr[n][1] +  fenstr[n][2];
                    xhpeixian2[xhcount] =fenstr[n][1] + (int.Parse(fenstr[n][2])+1).ToString() ;


                }

                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 7)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                        hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[2, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian1[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l + 1];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian2[tempn], 3);
                    l++;
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写灯丝电流
        private void button22_Click(object sender, EventArgs e)
        {
            int l = 0;// h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian1 = new string[100];
            string[] xhpeixian2 = new string[100];

            int xhcount = -1;
            read_zuobiao();
            read_kgl("灯丝电流");

            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {
                int n1 = fenstr[n].Length;

                if (n1 > 0)
                {

                    xh[++xhcount] = fenstr[n][0] + "-DJ电流";
                    xh[++xhcount] = fenstr[n][0] + "-2DJ电流";
                    //xhpeixian1[xhcount] = fenstr[n][1] + fenstr[n][2];
                   // xhpeixian2[xhcount] = fenstr[n][1] + (int.Parse(fenstr[n][2]) + 1).ToString();


                }

                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 7)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                        hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[2, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                   // AddText(textInsertPoint, xhpeixian1[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l + 1];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                   // AddText(textInsertPoint, xhpeixian2[tempn], 3);
                    l++;
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//道岔电流
        private void button24_Click(object sender, EventArgs e)
        {
            int l = 0;// h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian1 = new string[100];
            string[] xhpeixian2 = new string[100];
            string[] xhpeixian = new string[100];

            int xhcount = -1;
            read_zuobiao();
            read_kgl("道岔");

            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {
                int n1 = fenstr[n].Length;

                if (n1 > 0)
                {
                    xh[++xhcount] = fenstr[n][0] + "-1DQJ";
                    xhpeixian[xhcount]="1DQJ33";
                }

                int tempn = -1;
                while (++tempn <= xhcount)
                {

                    if (l > 15)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                            hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;
               
            }
            n = 0;
            while (n++ < count)
            {
                int n1 = fenstr[n].Length;

                if (n1 > 0)
                {
                    xh[++xhcount] = fenstr[n][0] + "道岔电流";
                    xhpeixian1[xhcount] = "1DQJ22";
                    xhpeixian2[xhcount] = "2DQJ121";
                }

                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 7)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                        hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[2, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);
                   
                    textInsertPoint[0] = zuobiao[0, 2 * l];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    if (xhpeixian1.Length > tempn)
                    AddText(textInsertPoint, xhpeixian1[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l + 1];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    if (xhpeixian2.Length > tempn)
                    AddText(textInsertPoint, xhpeixian2[tempn], 3);
                    l++;
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//表示电压
        private void button23_Click(object sender, EventArgs e)
        {
            int l = 0;// h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian1 = new string[100];
            string[] xhpeixian2 = new string[100];
            string wf=tempini.GetString("分线盘","外分","error");
            if(wf.CompareTo("error")==0)
                return;
            int xhcount = -1;
            read_zuobiao();
            read_kgl("道岔");

            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {
                int n1 = fenstr[n].Length;

                if (n1 > 0)
                {

                    xh[++xhcount] = fenstr[n][0] + "定表电压";
                    if (n1 > 1)
                    {
                        xhpeixian1[xhcount] = wf + "-" + fenstr[n][2] + fenstr[n][3];
                        xhpeixian2[xhcount] = wf + "-" + fenstr[n][2] + (int.Parse(fenstr[n][3]) + 2).ToString();
                    }
                    xh[++xhcount] = fenstr[n][0] + "反表电压";
                    if (n1 > 1)
                    {
                        xhpeixian1[xhcount] = wf + "-" + fenstr[n][2] + (int.Parse(fenstr[n][3]) + 2).ToString();
                        xhpeixian2[xhcount] = wf + "-" + fenstr[n][2] + (int.Parse(fenstr[n][3]) + 1).ToString();
                    }
                }

                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 7)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                        hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[2, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    if (xhpeixian1[tempn]!=null)
                    AddText(textInsertPoint, xhpeixian1[tempn], 2);

                    textInsertPoint[0] = zuobiao[0, 2 * l + 1];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    if (xhpeixian2[tempn]!=null)
                    AddText(textInsertPoint, xhpeixian2[tempn], 2);
                    l++;
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//电源屏
        private void button25_Click(object sender, EventArgs e)
        {
            int l = 0;// h = 0;
            int hcount = 0;
            string[] xh = new string[100];
            string[] xhpeixian1 = new string[100];
            string[] xhpeixian2 = new string[100];

            int xhcount = -1;
            read_zuobiao();
            read_kgl("电源");

            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;

            while (n++ < count)
            {
                int n1 = fenstr[n].Length;

                if (n1 > 0)
                {

                    xh[++xhcount] = fenstr[n][0] ;
               
                    //xhpeixian1[xhcount] = fenstr[n][1] + fenstr[n][2];
                    // xhpeixian2[xhcount] = fenstr[n][1] + (int.Parse(fenstr[n][2]) + 1).ToString();


                }

                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 7)
                    {
                        l = 0;
                        //h = h + 3;
                        //if (h > 7)
                        //{
                        //    h = 0;
                        hcount++;
                        //}
                    }
                    textInsertPoint[0] = zuobiao[2, l];
                    textInsertPoint[1] = zuobiao[3, 0] - hcount * 30;
                    AddText(textInsertPoint, xh[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    // AddText(textInsertPoint, xhpeixian1[tempn], 3);

                    textInsertPoint[0] = zuobiao[0, 2 * l + 1];
                    textInsertPoint[1] = zuobiao[3, 1] - hcount * 30;
                    // AddText(textInsertPoint, xhpeixian2[tempn], 3);
                    l++;
                }
                tempn = -1;
                xhcount = -1;

            }
        }
  //写自闭方向
        private void button26_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("自闭方向");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("分线盘", "内分", "error");
            if (nf.CompareTo("error") == 0)
                return;
            while (n++ < count)
            {

                xh[++xhcount] = fenstr[n][1] + "NFD-L";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-1";
                xh[++xhcount] = fenstr[n][1] + "JD-U";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-2";
                xh[++xhcount] = fenstr[n][1] + "JQD-H";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-3";
                xh[++xhcount] = fenstr[n][1] + "FZD-B";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-4";
                xh[++xhcount] = fenstr[n][1] + "1JG-H";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-14";
                xh[++xhcount] = fenstr[n][1] + "2JG-H";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-15";
                xh[++xhcount] = fenstr[n][1] + "3JG-H";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-16";
              
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//自闭方向逆
        private void button27_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("自闭方向逆向");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("分线盘", "内分", "error");
            if (nf.CompareTo("error") == 0)
                return;
            while (n++ < count)
            {

                xh[++xhcount] = fenstr[n][1] + "FD-L";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-1";
                xh[++xhcount] = fenstr[n][1] + "NJD-U";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-2";
                xh[++xhcount] = fenstr[n][1] + "NJQD-H";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-3";
                xh[++xhcount] = fenstr[n][1] + "NFZD-B";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-4";
                xh[++xhcount] = fenstr[n][1] + "NQFSD-B";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-5";
                xh[++xhcount] = fenstr[n][1] + "3LQ-H";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-14";
                xh[++xhcount] = fenstr[n][1] + "2LQ-H";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-15";
                xh[++xhcount] = fenstr[n][1] + "1LQ-H";
                xhpeixian[xhcount] = nf + "-" + fenstr[n][0] + "-16";
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//64D
        private void button28_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("64D");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("分线盘", "内分", "error");
            if (nf.CompareTo("error") == 0)
                return;
            while (n++ < count)
            {

                xh[++xhcount] = fenstr[n][1] + "BSA";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-7";
                xh[++xhcount] = fenstr[n][1] + "FUA";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-8";
                xh[++xhcount] = fenstr[n][1] + "SGA";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-9";
                xh[++xhcount] = fenstr[n][1] + "JBD-U";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-12";
                xh[++xhcount] = fenstr[n][1] + "JBD-H";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-13";
                xh[++xhcount] = fenstr[n][1] + "JBD-L";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-14";
                xh[++xhcount] = fenstr[n][1] + "FBD-U";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-15";
                xh[++xhcount] = fenstr[n][1] + "FBD-H";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-16";
                xh[++xhcount] = fenstr[n][1] + "FBD-L";
                xhpeixian[xhcount] = nf  + fenstr[n][0] + "-17";
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }
//写电缆测试
        private void button29_Click(object sender, EventArgs e)
        {
            int  h = -1;
            int lcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("外分");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            while (n++ < count)
            {
                int n1 = fenstr[n].Length;
                if (n1 > 0)
                {
                    xh[++xhcount] = fenstr[n][0] ;
                    xhpeixian[xhcount] = "F1-";
                   
                }
                if (n1 > 1)
                {
                    xhpeixian[xhcount] = fenstr[n][1];
                }
               

                int tempn = -1;

                while (++tempn <= xhcount)
                {
                    
                    if (h >= 15)
                    {
                        h = -1;
                        lcount++;
                    }
                    ++h;
                    textInsertPoint[0] = 0+lcount*50;
                    textInsertPoint[1] = zuobiao[4,h];
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = 0+(lcount)*50+24;
                    textInsertPoint[1] = zuobiao[4,h];
                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }

        private void button30_Click(object sender, EventArgs e)
        {
            int  h = -2;
            int lcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("电源对地");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            while (n++ < count)
            {
                int n1 = fenstr[n].Length;
                if (n1 > 0)
                {
                    xh[++xhcount] = fenstr[n][0];
                    xhpeixian[xhcount] = "";

                }
                if (n1 > 1)
                {
                    xhpeixian[xhcount] = fenstr[n][1];
                }


                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (h >= 14)
                    {
                        h = -2;
                        lcount++;
                    }
                    h=h+2;
                    textInsertPoint[0] = 0 + lcount * 50;
                    textInsertPoint[1] = zuobiao[4, h];
                    AddText(textInsertPoint, xh[tempn], 3);
                    //textInsertPoint[0] = 0 + (lcount) * 50 + 24;
                    //textInsertPoint[1] = zuobiao[4, h];
                    //AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }

        private void button31_Click(object sender, EventArgs e)
        {
            int l = 0, h = 0;
            int hcount = 0;
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            read_zuobiao();
            read_kgl("简单录入");
            int count = int.Parse(fenstr[0][0]);
            int n = 0;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            string nf = tempini.GetString("分线盘", "内分", "error");
            if (nf.CompareTo("error") == 0)
                return;
            while (n++ < count)
            {
                int n1 = fenstr[n].Length;
                if (n1 > 0)
                {
                   
                        xh[++xhcount] = fenstr[n][0];
                    
                }
                
                int tempn = -1;

                while (++tempn <= xhcount)
                {

                    if (l > 13)
                    {
                        l = 0;
                        h = h + 3;
                        if (h > 7)
                        {
                            h = 0;
                            hcount++;
                        }
                    }
                    textInsertPoint[0] = zuobiao[0, l];
                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                    AddText(textInsertPoint, xh[tempn], 3);
                    textInsertPoint[0] = zuobiao[0, l++];
                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                   // AddText(textInsertPoint, xhpeixian[tempn], 3);
                }
                tempn = -1;
                xhcount = -1;

            }
        }

        private void button32_Click(object sender, EventArgs e)
        {
            l = 0;
            h = 0;
            hcount = 0;
          
            read_zuobiao();
            ReadXhjDc(1);
            ReadJinZhan(1);
            Read64D(1);
            ReadDy1(1);
            ReadDy2(1);
            ReadLs(1);
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        public void ReadXhjDc(int style)
        {
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            int count;
            int n;
            string nf;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            switch (style)
            {
                #region style=1读第一类
                case 1:
                        read_kgl("信号机道岔");
                         count = int.Parse(fenstr[0][0]);
                         n = 0;
                        
                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {

                            if (fenstr[n][3].CompareTo("0") != 0)
                            {
                                xh[++xhcount] = fenstr[n][3] + "-H";
                                xhpeixian[xhcount] = nf + fenstr[n][0] + "-2";
                                xh[++xhcount] = fenstr[n][3] + "-B";
                                xhpeixian[xhcount] = nf + fenstr[n][0] + "-1";

                                int tempn = -1;

                                while (++tempn <= xhcount)
                                {

                                    if (l > 13)
                                    {
                                        l = 0;
                                        h = h + 3;
                                        if (h > 7)
                                        {
                                            h = 0;
                                            hcount++;
                                        }
                                    }
                                    textInsertPoint[0] = zuobiao[0, l];
                                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                    AddText(textInsertPoint, xh[tempn], 3);
                                    textInsertPoint[0] = zuobiao[0, l++];
                                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                                }
                                tempn = -1;
                                xhcount = -1;
                            }
                        }
                    break;
                #endregion

                #region style=2读第二类
                case 2:
                       read_kgl("信号机道岔");
                        count = int.Parse(fenstr[0][0]);
                        n = 0;
                      
                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {
                            if (fenstr[n][1].CompareTo("0") != 0)
                            {
                                if (fenstr[n][1].Substring(0, 1) == "D")
                                {
                                    xh[++xhcount] = fenstr[n][1] + "-B";
                                    xhpeixian[xhcount] = nf + fenstr[n][0] + "-15";
                                }
                                else
                                {
                                    xh[++xhcount] = fenstr[n][1] + "-L";
                                    xhpeixian[xhcount] = nf + fenstr[n][0] + "-16";
                                    xh[++xhcount] = fenstr[n][1] + "-B";
                                    xhpeixian[xhcount] = nf + fenstr[n][0] + "-15";
                                }

                                int tempn = -1;

                                while (++tempn <= xhcount)
                                {

                                    if (l > 13)
                                    {
                                        l = 0;
                                        h = h + 3;
                                        if (h > 7)
                                        {
                                            h = 0;
                                            hcount++;
                                        }
                                    }
                                    textInsertPoint[0] = zuobiao[0, l];
                                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                    AddText(textInsertPoint, xh[tempn], 3);
                                    textInsertPoint[0] = zuobiao[0, l++];
                                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                                }
                                tempn = -1;
                                xhcount = -1;
                            }
                        }
                        break;
                #endregion

                #region style=3读第三类
                case 3:
                       read_kgl("信号机道岔");
                        count = int.Parse(fenstr[0][0]);
                        n = 0;
                      
                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {
                            if (fenstr[n][1].CompareTo("0") != 0)
                            {
                                if (fenstr[n][1].Substring(0, 1) == "D")
                                {
                                    xh[++xhcount] = fenstr[n][1] + "A-B";
                                    xhpeixian[xhcount] = nf + fenstr[n][0] + "-14";
                                }
                                else
                                {
                                    xh[++xhcount] = fenstr[n][1] + "LA-L";
                                    xhpeixian[xhcount] = nf + fenstr[n][0] + "-13";
                                    xh[++xhcount] = fenstr[n][1] + "DA-B";
                                    xhpeixian[xhcount] = nf + fenstr[n][0] + "-14";
                                }

                                int tempn = -1;

                                while (++tempn <= xhcount)
                                {

                                    if (l > 13)
                                    {
                                        l = 0;
                                        h = h + 3;
                                        if (h > 7)
                                        {
                                            h = 0;
                                            hcount++;
                                        }
                                    }
                                    textInsertPoint[0] = zuobiao[0, l];
                                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                    AddText(textInsertPoint, xh[tempn], 3);
                                    textInsertPoint[0] = zuobiao[0, l++];
                                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                                }
                                tempn = -1;
                                xhcount = -1;
                            }
                        }
                        break;
                #endregion

                #region style=4读第四类
                case 4:
                        read_kgl("信号机道岔");
                        count = int.Parse(fenstr[0][0]);
                        n = 0;
                      
                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {
                            if (fenstr[n][2].CompareTo("0") != 0)
                            {
                                xh[++xhcount] = fenstr[n][2] + "DB-L";
                                xhpeixian[xhcount] = nf + fenstr[n][0] + "-7";
                                xh[++xhcount] = fenstr[n][2] + "FB-U";
                                xhpeixian[xhcount] = nf + fenstr[n][0] + "-8";

                                int tempn = -1;

                                while (++tempn <= xhcount)
                                {

                                    if (l > 13)
                                    {
                                        l = 0;
                                        h = h + 3;
                                        if (h > 7)
                                        {
                                            h = 0;
                                            hcount++;
                                        }
                                    }
                                    textInsertPoint[0] = zuobiao[0, l];
                                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                    AddText(textInsertPoint, xh[tempn], 3);
                                    textInsertPoint[0] = zuobiao[0, l++];
                                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                                }
                                tempn = -1;
                                xhcount = -1;
                            }
                        }
                        break;
                #endregion

                #region style=5读第五类
                case 5:
                        read_kgl("信号机道岔");
                        count = int.Parse(fenstr[0][0]);
                        n = 0;

                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {
                            if (fenstr[n][2].CompareTo("0") != 0)
                            {
                                xh[++xhcount] = fenstr[n][2] + "CA-H";
                                xhpeixian[xhcount] = "05-9";

                                int tempn = -1;

                                while (++tempn <= xhcount)
                                {

                                    if (l > 13)
                                    {
                                        l = 0;
                                        h = h + 3;
                                        if (h > 7)
                                        {
                                            h = 0;
                                            hcount++;
                                        }
                                    }
                                    textInsertPoint[0] = zuobiao[0, l];
                                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                    AddText(textInsertPoint, xh[tempn], 3);
                                    textInsertPoint[0] = zuobiao[0, l++];
                                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                                }
                                tempn = -1;
                                xhcount = -1;
                            }
                        }
                        break;
                #endregion

                #region style=8读第八类
                case 8:
                        read_kgl("信号机道岔");
                        count = int.Parse(fenstr[0][0]);
                        n = 0;

                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {
                            if (fenstr[n][2].CompareTo("0") != 0)
                            {
                                xh[++xhcount] = fenstr[n][2] + "-1DQJ";
                                xhpeixian[xhcount] = "1DQJ33";

                                int tempn = -1;

                                while (++tempn <= xhcount)
                                {

                                    if (l > 13)
                                    {
                                        l = 0;
                                        h = h + 3;
                                        if (h > 7)
                                        {
                                            h = 0;
                                            hcount++;
                                        }
                                    }
                                    textInsertPoint[0] = zuobiao[0, l];
                                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                    AddText(textInsertPoint, xh[tempn], 3);
                                    textInsertPoint[0] = zuobiao[0, l++];
                                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                                }
                                tempn = -1;
                                xhcount = -1;
                            }
                        }
                        break;
                #endregion

            }
        }

        public void ReadJinZhan(int style)
        {
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            int count;
            int n;
            string nf;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            switch (style)
            {
                 #region 读轨道
                case 1:
                    read_kgl("进站信号机");
                         count = int.Parse(fenstr[0][0]);
                         n = 0;
                        
                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {
                                xh[++xhcount] = fenstr[n][1] + "WG-H";
                                xhpeixian[xhcount] = nf + fenstr[n][0] + "-9";
                                xh[++xhcount] = fenstr[n][1] + "WG-B";
                                xhpeixian[xhcount] = nf + fenstr[n][0] + "-10";
                                xh[++xhcount] = fenstr[n][1] + "JG-H";
                                xhpeixian[xhcount] = nf + fenstr[n][0] + "-3";
                                int tempn = -1;

                                while (++tempn <= xhcount)
                                {

                                    if (l > 13)
                                    {
                                        l = 0;
                                        h = h + 3;
                                        if (h > 7)
                                        {
                                            h = 0;
                                            hcount++;
                                        }
                                    }
                                    textInsertPoint[0] = zuobiao[0, l];
                                    textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                    AddText(textInsertPoint, xh[tempn], 3);
                                    textInsertPoint[0] = zuobiao[0, l++];
                                    textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                    AddText(textInsertPoint, xhpeixian[tempn], 3);
                                }
                                tempn = -1;
                                xhcount = -1;
                        }
                    break;
                #endregion

                 #region 读信号复示
                case 2:
                    read_kgl("进站信号机");
                         count = int.Parse(fenstr[0][0]);
                         n = 0;
                        
                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {
                            xh[++xhcount] = fenstr[n][2] + "-B";
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-15";
                            xh[++xhcount] = fenstr[n][1] + "-L";
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-16";
                            xh[++xhcount] = fenstr[n][1] + "-B";
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-17";
                            xh[++xhcount] = fenstr[n][1] + "-H";
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-18";
                            int tempn = -1;

                            while (++tempn <= xhcount)
                            {

                                if (l > 13)
                                {
                                    l = 0;
                                    h = h + 3;
                                    if (h > 7)
                                    {
                                        h = 0;
                                        hcount++;
                                    }
                                }
                                textInsertPoint[0] = zuobiao[0, l];
                                textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                AddText(textInsertPoint, xh[tempn], 3);
                                textInsertPoint[0] = zuobiao[0, l++];
                                textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                AddText(textInsertPoint, xhpeixian[tempn], 3);
                            }
                            tempn = -1;
                            xhcount = -1;
                        }
                    break;
                #endregion

                 #region 读进路按钮
                case 3:
                    read_kgl("进站信号机");
                         count = int.Parse(fenstr[0][0]);
                         n = 0;
                        
                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {
                            xh[++xhcount] = fenstr[n][2] + "A-B";
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-14";
                            xh[++xhcount] = fenstr[n][1] + "TA-L";
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-5";
                            xh[++xhcount] = fenstr[n][1] + "LA-L";
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-13";
                           
                            int tempn = -1;

                            while (++tempn <= xhcount)
                            {

                                if (l > 13)
                                {
                                    l = 0;
                                    h = h + 3;
                                    if (h > 7)
                                    {
                                        h = 0;
                                        hcount++;
                                    }
                                }
                                textInsertPoint[0] = zuobiao[0, l];
                                textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                AddText(textInsertPoint, xh[tempn], 3);
                                textInsertPoint[0] = zuobiao[0, l++];
                                textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                AddText(textInsertPoint, xhpeixian[tempn], 3);
                            }
                            tempn = -1;
                            xhcount = -1;
                        }
                    break;
                #endregion

                 #region 读铅封
                case 6:
                    read_kgl("进站信号机");
                         count = int.Parse(fenstr[0][0]);
                         n = 0;
                        
                        nf = tempini.GetString("分线盘", "内分", "error");
                        if (nf.CompareTo("error") == 0)
                            return;
                        while (n++ < count)
                        {
                            xh[++xhcount] = fenstr[n][1] + "YZSA-B";
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-2";
                            xh[++xhcount] = fenstr[n][1] + "YA-B";
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-7";

                            int tempn = -1;

                            while (++tempn <= xhcount)
                            {

                                if (l > 13)
                                {
                                    l = 0;
                                    h = h + 3;
                                    if (h > 7)
                                    {
                                        h = 0;
                                        hcount++;
                                    }
                                }
                                textInsertPoint[0] = zuobiao[0, l];
                                textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                AddText(textInsertPoint, xh[tempn], 3);
                                textInsertPoint[0] = zuobiao[0, l++];
                                textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                AddText(textInsertPoint, xhpeixian[tempn], 3);
                            }
                            tempn = -1;
                            xhcount = -1;
                        }
                    break;
                #endregion
            }
        }

        public void ReadDy1(int style)
        {
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            int count;
            int n;
            string nf;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            switch (style)
            {
                #region 表示灯
                case 5:
                    read_kgl("电源1");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        xh[++xhcount] = fenstr[n][1] + "DR-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-1";
                        xh[++xhcount] = fenstr[n][1] + "LR-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-2";
                        xh[++xhcount] = "JC-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-6";
                        int tempn = -1;

                        while (++tempn <= xhcount)
                        {

                            if (l > 13)
                            {
                                l = 0;
                                h = h + 3;
                                if (h > 7)
                                {
                                    h = 0;
                                    hcount++;
                                }
                            }
                            textInsertPoint[0] = zuobiao[0, l];
                            textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                            AddText(textInsertPoint, xh[tempn], 3);
                            textInsertPoint[0] = zuobiao[0, l++];
                            textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                            AddText(textInsertPoint, xhpeixian[tempn], 3);
                        }
                        tempn = -1;
                        xhcount = -1;
                    }
                    break;
                #endregion
            } 
        }

        public void ReadDy2(int style)
        {
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            int count;
            int n;
            string nf;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            switch (style)
            {
                #region 表示灯
                case 5:
                    read_kgl("电源2");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        xh[++xhcount] = fenstr[n][1] + "DR-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-1";
                        xh[++xhcount] = fenstr[n][1] + "LR-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-2";
                        xh[++xhcount] = "FDY-U";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-7";
                        xh[++xhcount] = "ZDY-L";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-8";
                        xh[++xhcount] = "夜-U";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-17";
                        xh[++xhcount] = "昼-L";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-18";
                        int tempn = -1;

                        while (++tempn <= xhcount)
                        {

                            if (l > 13)
                            {
                                l = 0;
                                h = h + 3;
                                if (h > 7)
                                {
                                    h = 0;
                                    hcount++;
                                }
                            }
                            textInsertPoint[0] = zuobiao[0, l];
                            textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                            AddText(textInsertPoint, xh[tempn], 3);
                            textInsertPoint[0] = zuobiao[0, l++];
                            textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                            AddText(textInsertPoint, xhpeixian[tempn], 3);
                        }
                        tempn = -1;
                        xhcount = -1;
                    }
                    break;
                #endregion
            } 
        }

        public void ReadFx(int style)
        {
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            int count;
            int n;
            string nf;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            switch (style)
            {
                #region 表示灯
                case 5:
                    read_kgl("方向");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        xh[++xhcount] = fenstr[n][1] + "ZQ-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-6";
                        xh[++xhcount] = fenstr[n][1] + "PL-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-7";
                        xh[++xhcount] = fenstr[n][1] + "ZD-L";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-9";
                        xh[++xhcount] = fenstr[n][1] + "ZF-U";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-11";
                     
                        int tempn = -1;

                        while (++tempn <= xhcount)
                        {

                            if (l > 13)
                            {
                                l = 0;
                                h = h + 3;
                                if (h > 7)
                                {
                                    h = 0;
                                    hcount++;
                                }
                            }
                            textInsertPoint[0] = zuobiao[0, l];
                            textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                            AddText(textInsertPoint, xh[tempn], 3);
                            textInsertPoint[0] = zuobiao[0, l++];
                            textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                            AddText(textInsertPoint, xhpeixian[tempn], 3);
                        }
                        tempn = -1;
                        xhcount = -1;
                    }
                    break;
                #endregion

                #region 铅封
                case 6:
                      read_kgl("方向");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        xh[++xhcount] = fenstr[n][1] + "ZR-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-4";
                      
                        int tempn = -1;

                        while (++tempn <= xhcount)
                        {

                            if (l > 13)
                            {
                                l = 0;
                                h = h + 3;
                                if (h > 7)
                                {
                                    h = 0;
                                    hcount++;
                                }
                            }
                            textInsertPoint[0] = zuobiao[0, l];
                            textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                            AddText(textInsertPoint, xh[tempn], 3);
                            textInsertPoint[0] = zuobiao[0, l++];
                            textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                            AddText(textInsertPoint, xhpeixian[tempn], 3);
                        }
                        tempn = -1;
                        xhcount = -1;
                    }
                    break;

                #endregion
                
                #region 方向继电器
                case 8:
                    read_kgl("方向");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        xh[++xhcount] = fenstr[n][1] + "LJJ";
                        xhpeixian[xhcount] = "LJJ83";
                        xh[++xhcount] = fenstr[n][1] + "LFJ";
                        xhpeixian[xhcount] = "LFJ83";
                        xh[++xhcount] = fenstr[n][1] + "DJJ";
                        xhpeixian[xhcount] = "DJJ83";
                        xh[++xhcount] = fenstr[n][1] + "DFJ";
                        xhpeixian[xhcount] = "DFJ83";

                        int tempn = -1;

                        while (++tempn <= xhcount)
                        {

                            if (l > 13)
                            {
                                l = 0;
                                h = h + 3;
                                if (h > 7)
                                {
                                    h = 0;
                                    hcount++;
                                }
                            }
                            textInsertPoint[0] = zuobiao[0, l];
                            textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                            AddText(textInsertPoint, xh[tempn], 3);
                            textInsertPoint[0] = zuobiao[0, l++];
                            textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                            AddText(textInsertPoint, xhpeixian[tempn], 3);
                        }
                        tempn = -1;
                        xhcount = -1;
                    }
                    break;
                #endregion

            } 
        }

        public void Read64D(int style)
        {
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            int count;
            int n;
            string nf;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            switch (style)
            {
                #region 表示灯
                case 5:
                    read_kgl("64D");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        xh[++xhcount] = fenstr[n][1] + "JBD-U";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-12";
                        xh[++xhcount] = fenstr[n][1] + "JBD-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-13";
                        xh[++xhcount] = fenstr[n][1] + "JBD-L";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-14";
                        xh[++xhcount] = fenstr[n][1] + "FBD-U";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-15";
                        xh[++xhcount] = fenstr[n][1] + "FBD-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-16";
                        xh[++xhcount] = fenstr[n][1] + "FBD-L";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-17";
                        xh[++xhcount] = fenstr[n][1] + "BSA-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-7";
                        xh[++xhcount] = fenstr[n][1] + "FUA-H";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-8";

                        int tempn = -1;

                        while (++tempn <= xhcount)
                        {

                            if (l > 13)
                            {
                                l = 0;
                                h = h + 3;
                                if (h > 7)
                                {
                                    h = 0;
                                    hcount++;
                                }
                            }
                            textInsertPoint[0] = zuobiao[0, l];
                            textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                            AddText(textInsertPoint, xh[tempn], 3);
                            textInsertPoint[0] = zuobiao[0, l++];
                            textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                            AddText(textInsertPoint, xhpeixian[tempn], 3);
                        }
                        tempn = -1;
                        xhcount = -1;
                    }
                    break;
                #endregion

                #region 铅封
                case 6:
                    read_kgl("64D");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        xh[++xhcount] = fenstr[n][1] + "SGA";
                        xhpeixian[xhcount] = nf + fenstr[n][0] + "-9";

                        int tempn = -1;

                        while (++tempn <= xhcount)
                        {

                            if (l > 13)
                            {
                                l = 0;
                                h = h + 3;
                                if (h > 7)
                                {
                                    h = 0;
                                    hcount++;
                                }
                            }
                            textInsertPoint[0] = zuobiao[0, l];
                            textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                            AddText(textInsertPoint, xh[tempn], 3);
                            textInsertPoint[0] = zuobiao[0, l++];
                            textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                            AddText(textInsertPoint, xhpeixian[tempn], 3);
                        }
                        tempn = -1;
                        xhcount = -1;
                    }
                    break;

                #endregion

            } 
        }

        public void ReadLs(int style)
        {
            string[] xh = new string[18];
            string[] xhpeixian = new string[18];
            int xhcount = -1;
            int count;
            int n;
            string nf;
            double[] textInsertPoint = new double[3];
            textInsertPoint[0] = 127; textInsertPoint[1] = 273; textInsertPoint[2] = 0;
            
            switch (style)
            {

                #region 轨道
                case 1:
                    read_kgl("零散");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        if (fenstr[n][3] == "1")
                        {
                            xh[++xhcount] = fenstr[n][1];
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-" + fenstr[n][2];
                        
                            int tempn = -1;

                            while (++tempn <= xhcount)
                            {

                                if (l > 13)
                                {
                                    l = 0;
                                    h = h + 3;
                                    if (h > 7)
                                    {
                                        h = 0;
                                        hcount++;
                                    }
                                }
                                textInsertPoint[0] = zuobiao[0, l];
                                textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                AddText(textInsertPoint, xh[tempn], 3);
                                textInsertPoint[0] = zuobiao[0, l++];
                                textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                AddText(textInsertPoint, xhpeixian[tempn], 3);
                            }
                            tempn = -1;
                            xhcount = -1;
                        }
                    }
                    break;
                #endregion

                #region 铅封
                case 6:
                    read_kgl("零散");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        if (fenstr[n][3] == "6")
                        {
                            xh[++xhcount] = fenstr[n][1];
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-" + fenstr[n][2];

                            int tempn = -1;

                            while (++tempn <= xhcount)
                            {

                                if (l > 13)
                                {
                                    l = 0;
                                    h = h + 3;
                                    if (h > 7)
                                    {
                                        h = 0;
                                        hcount++;
                                    }
                                }
                                textInsertPoint[0] = zuobiao[0, l];
                                textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                AddText(textInsertPoint, xh[tempn], 3);
                                textInsertPoint[0] = zuobiao[0, l++];
                                textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                AddText(textInsertPoint, xhpeixian[tempn], 3);
                            }
                            tempn = -1;
                            xhcount = -1;
                        }
                    }
                    break;
                #endregion

                #region 表示灯
                case 5:
                    read_kgl("零散");
                    count = int.Parse(fenstr[0][0]);
                    n = 0;

                    nf = tempini.GetString("分线盘", "内分", "error");
                    if (nf.CompareTo("error") == 0)
                        return;
                    while (n++ < count)
                    {
                        if (fenstr[n][3] == "5")
                        {
                            xh[++xhcount] = fenstr[n][1];
                            xhpeixian[xhcount] = nf + fenstr[n][0] + "-" + fenstr[n][2];

                            int tempn = -1;

                            while (++tempn <= xhcount)
                            {

                                if (l > 13)
                                {
                                    l = 0;
                                    h = h + 3;
                                    if (h > 7)
                                    {
                                        h = 0;
                                        hcount++;
                                    }
                                }
                                textInsertPoint[0] = zuobiao[0, l];
                                textInsertPoint[1] = zuobiao[1, h] - hcount * 160;
                                AddText(textInsertPoint, xh[tempn], 3);
                                textInsertPoint[0] = zuobiao[0, l++];
                                textInsertPoint[1] = zuobiao[1, h + 1] - hcount * 160;
                                AddText(textInsertPoint, xhpeixian[tempn], 3);
                            }
                            tempn = -1;
                            xhcount = -1;
                        }
                    }
                    break;
                #endregion

            } 
        }
        private void button2lei_Click(object sender, EventArgs e)
        {
            l = 0;
            h = 0;
            hcount = 0;

            read_zuobiao();
            ReadXhjDc(2);
            ReadJinZhan(2);
            Read64D(2);
            ReadDy1(2);
            ReadDy2(2);
            ReadLs(2);
        }

        private void button3lei_Click(object sender, EventArgs e)
        {
            l = 0;
            h = 0;
            hcount = 0;

            read_zuobiao();
            ReadXhjDc(3);
            ReadJinZhan(3);
            Read64D(3);
            ReadDy1(3);
            ReadDy2(3);
            ReadLs(3);
        }

        private void button4lei_Click(object sender, EventArgs e)
        {
            l = 0;
            h = 0;
            hcount = 0;

            read_zuobiao();
            ReadXhjDc(4);
            ReadJinZhan(4);
            Read64D(4);
            ReadDy1(4);
            ReadDy2(4);
            ReadLs(4);
        }

        private void button5lei_Click(object sender, EventArgs e)
        {
            l = 0;
            h = 0;
            hcount = 0;

            read_zuobiao();
            ReadXhjDc(5);
            ReadJinZhan(5);
            Read64D(5);
            ReadDy1(5);
            ReadDy2(5);
            ReadLs(5);
        }

        private void button6lei_Click(object sender, EventArgs e)
        {
            l = 0;
            h = 0;
            hcount = 0;

            read_zuobiao();
            ReadXhjDc(6);
            ReadJinZhan(6);
            ReadFx(6);
            Read64D(6);
            ReadDy1(6);
            ReadDy2(6);
            ReadLs(6);
        }

        private void button7lei_Click(object sender, EventArgs e)
        {
            l = 0;
            h = 0;
            hcount = 0;

            read_zuobiao();
            ReadXhjDc(7);
            ReadJinZhan(7);
            Read64D(7);
            ReadDy1(7);
            ReadDy2(7);
            ReadLs(7);
        }

        private void button8lei_Click(object sender, EventArgs e)
        {
            l = 0;
            h = 0;
            hcount = 0;

            read_zuobiao();
            ReadXhjDc(8);
            ReadJinZhan(8);
            Read64D(8);
            ReadDy1(8);
            ReadDy2(8);
            ReadLs(8);
        }


    }
}

namespace Utilities
{
    /// <summary> 
    /// Provides methods for reading and writing to an INI file. 
    /// </summary> 
    public class IniFile
    {
        /// <summary> 
        /// The maximum size of a section in an ini file. 
        /// </summary> 
        /// <remarks> 
        /// This property defines the maximum size of the buffers 
        /// used to retreive data from an ini file.  This value is 
        /// the maximum allowed by the win32 functions 
        /// GetPrivateProfileSectionNames() or 
        /// GetPrivateProfileString(). 
        /// </remarks> 
        public const int MaxSectionSize = 32767; // 32 KB 

        //The path of the file we are operating on. 
        private string m_path;

        #region P/Invoke declares

        /// <summary> 
        /// A static class that provides the win32 P/Invoke signatures 
        /// used by this class. 
        /// </summary> 
        /// <remarks> 
        /// Note:  In each of the declarations below, we explicitly set CharSet to 
        /// Auto.  By default in C#, CharSet is set to Ansi, which reduces 
        /// performance on windows 2000 and above due to needing to convert strings 
        /// from Unicode (the native format for all .Net strings) to Ansi before 
        /// marshalling.  Using Auto lets the marshaller select the Unicode version of 
        /// these functions when available. 
        /// </remarks> 
        [System.Security.SuppressUnmanagedCodeSecurity]
        private static class NativeMethods
        {
            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int GetPrivateProfileSectionNames(IntPtr lpszReturnBuffer,
                                                                   uint nSize,
                                                                   string lpFileName);

            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern uint GetPrivateProfileString(string lpAppName,
                                                              string lpKeyName,
                                                              string lpDefault,
                                                              StringBuilder lpReturnedString,
                                                              int nSize,
                                                              string lpFileName);

            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern uint GetPrivateProfileString(string lpAppName,
                                                              string lpKeyName,
                                                              string lpDefault,
                                                              [In, Out] char[] lpReturnedString,
                                                              int nSize,
                                                              string lpFileName);

            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int GetPrivateProfileString(string lpAppName,
                                                             string lpKeyName,
                                                             string lpDefault,
                                                             IntPtr lpReturnedString,
                                                             uint nSize,
                                                             string lpFileName);

            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int GetPrivateProfileInt(string lpAppName,
                                                          string lpKeyName,
                                                          int lpDefault,
                                                          string lpFileName);

            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern int GetPrivateProfileSection(string lpAppName,
                                                              IntPtr lpReturnedString,
                                                              uint nSize,
                                                              string lpFileName);

            //We explicitly enable the SetLastError attribute here because 
            // WritePrivateProfileString returns errors via SetLastError. 
            // Failure to set this can result in errors being lost during 
            // the marshal back to managed code. 
            [DllImport("kernel32.dll", CharSet = CharSet.Auto, SetLastError = true)]
            public static extern bool WritePrivateProfileString(string lpAppName,
                                                                string lpKeyName,
                                                                string lpString,
                                                                string lpFileName);


        }
        #endregion

        /// <summary> 
        /// Initializes a new instance of the <see cref="IniFile"/> class. 
        /// </summary> 
        /// <param name="path">The ini file to read and write from.</param> 
        public IniFile(string path)
        {
            //Convert to the full path.  Because of backward compatibility, 
            // the win32 functions tend to assume the path should be the 
            // root Windows directory if it is not specified.  By calling 
            // GetFullPath, we make sure we are always passing the full path 
            // the win32 functions. 
            m_path = System.IO.Path.GetFullPath(path);
        }

        /// <summary> 
        /// Gets the full path of ini file this object instance is operating on. 
        /// </summary> 
        /// <value>A file path.</value> 
        public string Path
        {
            get
            {
                return m_path;
            }
        }

        #region Get Value Methods

        /// <summary> 
        /// Gets the value of a setting in an ini file as a <see cref="T:System.String"/>. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to read from.</param> 
        /// <param name="keyName">The name of the key in section to read.</param> 
        /// <param name="defaultValue">The default value to return if the key 
        /// cannot be found.</param> 
        /// <returns>The value of the key, if found.  Otherwise, returns 
        /// <paramref name="defaultValue"/></returns> 
        /// <remarks> 
        /// The retreived value must be less than 32KB in length. 
        /// </remarks> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> or <paramref name="keyName"/> are 
        /// a null reference  (Nothing in VB) 
        /// </exception> 
        public string GetString(string sectionName,
                                string keyName,
                                string defaultValue)
        {
            if (sectionName == null)
                throw new ArgumentNullException("sectionName");

            if (keyName == null)
                throw new ArgumentNullException("keyName");

            StringBuilder retval = new StringBuilder(IniFile.MaxSectionSize);

            NativeMethods.GetPrivateProfileString(sectionName,
                                                  keyName,
                                                  defaultValue,
                                                  retval,
                                                  IniFile.MaxSectionSize,
                                                  m_path);

            return retval.ToString();
        }

        /// <summary> 
        /// Gets the value of a setting in an ini file as a <see cref="T:System.Int16"/>. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to read from.</param> 
        /// <param name="keyName">The name of the key in section to read.</param> 
        /// <param name="defaultValue">The default value to return if the key 
        /// cannot be found.</param> 
        /// <returns>The value of the key, if found.  Otherwise, returns 
        /// <paramref name="defaultValue"/>.</returns> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> or <paramref name="keyName"/> are 
        /// a null reference  (Nothing in VB) 
        /// </exception> 
        public int GetInt16(string sectionName,
                            string keyName,
                            short defaultValue)
        {
            int retval = GetInt32(sectionName, keyName, defaultValue);

            return Convert.ToInt16(retval);
        }

        /// <summary> 
        /// Gets the value of a setting in an ini file as a <see cref="T:System.Int32"/>. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to read from.</param> 
        /// <param name="keyName">The name of the key in section to read.</param> 
        /// <param name="defaultValue">The default value to return if the key 
        /// cannot be found.</param> 
        /// <returns>The value of the key, if found.  Otherwise, returns 
        /// <paramref name="defaultValue"/></returns> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> or <paramref name="keyName"/> are 
        /// a null reference  (Nothing in VB) 
        /// </exception> 
        public int GetInt32(string sectionName,
                            string keyName,
                            int defaultValue)
        {
            if (sectionName == null)
                throw new ArgumentNullException("sectionName");

            if (keyName == null)
                throw new ArgumentNullException("keyName");


            return NativeMethods.GetPrivateProfileInt(sectionName, keyName, defaultValue, m_path);
        }

        /// <summary> 
        /// Gets the value of a setting in an ini file as a <see cref="T:System.Double"/>. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to read from.</param> 
        /// <param name="keyName">The name of the key in section to read.</param> 
        /// <param name="defaultValue">The default value to return if the key 
        /// cannot be found.</param> 
        /// <returns>The value of the key, if found.  Otherwise, returns 
        /// <paramref name="defaultValue"/></returns> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> or <paramref name="keyName"/> are 
        /// a null reference  (Nothing in VB) 
        /// </exception> 
        public double GetDouble(string sectionName,
                                string keyName,
                                double defaultValue)
        {
            string retval = GetString(sectionName, keyName, "");

            if (retval == null || retval.Length == 0)
            {
                return defaultValue;
            }

            return Convert.ToDouble(retval, CultureInfo.InvariantCulture);
        }

        #endregion

        #region GetSectionValues Methods

        /// <summary> 
        /// Gets all of the values in a section as a list. 
        /// </summary> 
        /// <param name="sectionName"> 
        /// Name of the section to retrieve values from. 
        /// </param> 
        /// <returns> 
        /// A <see cref="List{T}"/> containing <see cref="KeyValuePair{T1, T2}"/> objects 
        /// that describe this section.  Use this verison if a section may contain 
        /// multiple items with the same key value.  If you know that a section 
        /// cannot contain multiple values with the same key name or you don't 
        /// care about the duplicates, use the more convenient 
        /// <see cref="GetSectionValues"/> function. 
        /// </returns> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> is a null reference  (Nothing in VB) 
        /// </exception> 
        public List<KeyValuePair<string, string>> GetSectionValuesAsList(string sectionName)
        {
            List<KeyValuePair<string, string>> retval;
            string[] keyValuePairs;
            string key, value;
            int equalSignPos;

            if (sectionName == null)
                throw new ArgumentNullException("sectionName");

            //Allocate a buffer for the returned section names. 
            IntPtr ptr = Marshal.AllocCoTaskMem(IniFile.MaxSectionSize);

            try
            {
                //Get the section key/value pairs into the buffer. 
                int len = NativeMethods.GetPrivateProfileSection(sectionName,
                                                                 ptr,
                                                                 IniFile.MaxSectionSize,
                                                                 m_path);

                keyValuePairs = ConvertNullSeperatedStringToStringArray(ptr, len);
            }
            finally
            {
                //Free the buffer 
                Marshal.FreeCoTaskMem(ptr);
            }

            //Parse keyValue pairs and add them to the list. 
            retval = new List<KeyValuePair<string, string>>(keyValuePairs.Length);

            for (int i = 0; i < keyValuePairs.Length; ++i)
            {
                //Parse the "key=value" string into its constituent parts 
                equalSignPos = keyValuePairs[i].IndexOf('=');

                key = keyValuePairs[i].Substring(0, equalSignPos);

                value = keyValuePairs[i].Substring(equalSignPos + 1,
                                                   keyValuePairs[i].Length - equalSignPos - 1);

                retval.Add(new KeyValuePair<string, string>(key, value));
            }

            return retval;
        }

        /// <summary> 
        /// Gets all of the values in a section as a dictionary. 
        /// </summary> 
        /// <param name="sectionName"> 
        /// Name of the section to retrieve values from. 
        /// </param> 
        /// <returns> 
        /// A <see cref="Dictionary{T, T}"/> containing the key/value 
        /// pairs found in this section.   
        /// </returns> 
        /// <remarks> 
        /// If a section contains more than one key with the same name, 
        /// this function only returns the first instance.  If you need to 
        /// get all key/value pairs within a section even when keys have the 
        /// same name, use <see cref="GetSectionValuesAsList"/>. 
        /// </remarks> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> is a null reference  (Nothing in VB) 
        /// </exception> 
        public Dictionary<string, string> GetSectionValues(string sectionName)
        {
            List<KeyValuePair<string, string>> keyValuePairs;
            Dictionary<string, string> retval;

            keyValuePairs = GetSectionValuesAsList(sectionName);

            //Convert list into a dictionary. 
            retval = new Dictionary<string, string>(keyValuePairs.Count);

            foreach (KeyValuePair<string, string> keyValuePair in keyValuePairs)
            {
                //Skip any key we have already seen. 
                if (!retval.ContainsKey(keyValuePair.Key))
                {
                    retval.Add(keyValuePair.Key, keyValuePair.Value);
                }
            }

            return retval;
        }

        #endregion

        #region Get Key/Section Names

        /// <summary> 
        /// Gets the names of all keys under a specific section in the ini file. 
        /// </summary> 
        /// <param name="sectionName"> 
        /// The name of the section to read key names from. 
        /// </param> 
        /// <returns>An array of key names.</returns> 
        /// <remarks> 
        /// The total length of all key names in the section must be 
        /// less than 32KB in length. 
        /// </remarks> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> is a null reference  (Nothing in VB) 
        /// </exception> 
        public string[] GetKeyNames(string sectionName)
        {
            int len;
            string[] retval;

            if (sectionName == null)
                throw new ArgumentNullException("sectionName");

            //Allocate a buffer for the returned section names. 
            IntPtr ptr = Marshal.AllocCoTaskMem(IniFile.MaxSectionSize);

            try
            {
                //Get the section names into the buffer. 
                len = NativeMethods.GetPrivateProfileString(sectionName,
                                                            null,
                                                            null,
                                                            ptr,
                                                            IniFile.MaxSectionSize,
                                                            m_path);

                retval = ConvertNullSeperatedStringToStringArray(ptr, len);
            }
            finally
            {
                //Free the buffer 
                Marshal.FreeCoTaskMem(ptr);
            }

            return retval;
        }

        /// <summary> 
        /// Gets the names of all sections in the ini file. 
        /// </summary> 
        /// <returns>An array of section names.</returns> 
        /// <remarks> 
        /// The total length of all section names in the section must be 
        /// less than 32KB in length. 
        /// </remarks> 
        public string[] GetSectionNames()
        {
            string[] retval;
            int len;

            //Allocate a buffer for the returned section names. 
            IntPtr ptr = Marshal.AllocCoTaskMem(IniFile.MaxSectionSize);

            try
            {
                //Get the section names into the buffer. 
                len = NativeMethods.GetPrivateProfileSectionNames(ptr,
                    IniFile.MaxSectionSize, m_path);

                retval = ConvertNullSeperatedStringToStringArray(ptr, len);
            }
            finally
            {
                //Free the buffer 
                Marshal.FreeCoTaskMem(ptr);
            }

            return retval;
        }

        /// <summary> 
        /// Converts the null seperated pointer to a string into a string array. 
        /// </summary> 
        /// <param name="ptr">A pointer to string data.</param> 
        /// <param name="valLength"> 
        /// Length of the data pointed to by <paramref name="ptr"/>. 
        /// </param> 
        /// <returns> 
        /// An array of strings; one for each null found in the array of characters pointed 
        /// at by <paramref name="ptr"/>. 
        /// </returns> 
        private static string[] ConvertNullSeperatedStringToStringArray(IntPtr ptr, int valLength)
        {
            string[] retval;

            if (valLength == 0)
            {
                //Return an empty array. 
                retval = new string[0];
            }
            else
            {
                //Convert the buffer into a string.  Decrease the length 
                //by 1 so that we remove the second null off the end. 
                string buff = Marshal.PtrToStringAuto(ptr, valLength - 1);

                //Parse the buffer into an array of strings by searching for nulls. 
                retval = buff.Split('\0');
            }

            return retval;
        }

        #endregion

        #region Write Methods

        /// <summary> 
        /// Writes a <see cref="T:System.String"/> value to the ini file. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to write to .</param> 
        /// <param name="keyName">The name of the key to write to.</param> 
        /// <param name="value">The string value to write</param> 
        /// <exception cref="T:System.ComponentModel.Win32Exception"> 
        /// The write failed. 
        /// </exception> 
        private void WriteValueInternal(string sectionName, string keyName, string value)
        {
            if (!NativeMethods.WritePrivateProfileString(sectionName, keyName, value, m_path))
            {
                throw new System.ComponentModel.Win32Exception();
            }
        }

        /// <summary> 
        /// Writes a <see cref="T:System.String"/> value to the ini file. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to write to .</param> 
        /// <param name="keyName">The name of the key to write to.</param> 
        /// <param name="value">The string value to write</param> 
        /// <exception cref="T:System.ComponentModel.Win32Exception"> 
        /// The write failed. 
        /// </exception> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> or <paramref name="keyName"/> or 
        /// <paramref name="value"/>  are a null reference  (Nothing in VB) 
        /// </exception> 
        public void WriteValue(string sectionName, string keyName, string value)
        {
            if (sectionName == null)
                throw new ArgumentNullException("sectionName");

            if (keyName == null)
                throw new ArgumentNullException("keyName");

            if (value == null)
                throw new ArgumentNullException("value");

            WriteValueInternal(sectionName, keyName, value);
        }

        /// <summary> 
        /// Writes an <see cref="T:System.Int16"/> value to the ini file. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to write to .</param> 
        /// <param name="keyName">The name of the key to write to.</param> 
        /// <param name="value">The value to write</param> 
        /// <exception cref="T:System.ComponentModel.Win32Exception"> 
        /// The write failed. 
        /// </exception> 
        public void WriteValue(string sectionName, string keyName, short value)
        {
            WriteValue(sectionName, keyName, (int)value);
        }

        /// <summary> 
        /// Writes an <see cref="T:System.Int32"/> value to the ini file. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to write to .</param> 
        /// <param name="keyName">The name of the key to write to.</param> 
        /// <param name="value">The value to write</param> 
        /// <exception cref="T:System.ComponentModel.Win32Exception"> 
        /// The write failed. 
        /// </exception> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> or <paramref name="keyName"/> are 
        /// a null reference  (Nothing in VB) 
        /// </exception> 
        public void WriteValue(string sectionName, string keyName, int value)
        {
            WriteValue(sectionName, keyName, value.ToString(CultureInfo.InvariantCulture));
        }

        /// <summary> 
        /// Writes an <see cref="T:System.Single"/> value to the ini file. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to write to .</param> 
        /// <param name="keyName">The name of the key to write to.</param> 
        /// <param name="value">The value to write</param> 
        /// <exception cref="T:System.ComponentModel.Win32Exception"> 
        /// The write failed. 
        /// </exception> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> or <paramref name="keyName"/> are 
        /// a null reference  (Nothing in VB) 
        /// </exception> 
        public void WriteValue(string sectionName, string keyName, float value)
        {
            WriteValue(sectionName, keyName, value.ToString(CultureInfo.InvariantCulture));
        }

        /// <summary> 
        /// Writes an <see cref="T:System.Double"/> value to the ini file. 
        /// </summary> 
        /// <param name="sectionName">The name of the section to write to .</param> 
        /// <param name="keyName">The name of the key to write to.</param> 
        /// <param name="value">The value to write</param> 
        /// <exception cref="T:System.ComponentModel.Win32Exception"> 
        /// The write failed. 
        /// </exception> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> or <paramref name="keyName"/> are 
        /// a null reference  (Nothing in VB) 
        /// </exception> 
        public void WriteValue(string sectionName, string keyName, double value)
        {
            WriteValue(sectionName, keyName, value.ToString(CultureInfo.InvariantCulture));
        }

        #endregion

        #region Delete Methods

        /// <summary> 
        /// Deletes the specified key from the specified section. 
        /// </summary> 
        /// <param name="sectionName"> 
        /// Name of the section to remove the key from. 
        /// </param> 
        /// <param name="keyName"> 
        /// Name of the key to remove. 
        /// </param> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> or <paramref name="keyName"/> are 
        /// a null reference  (Nothing in VB) 
        /// </exception> 
        public void DeleteKey(string sectionName, string keyName)
        {
            if (sectionName == null)
                throw new ArgumentNullException("sectionName");

            if (keyName == null)
                throw new ArgumentNullException("keyName");

            WriteValueInternal(sectionName, keyName, null);
        }

        /// <summary> 
        /// Deletes a section from the ini file. 
        /// </summary> 
        /// <param name="sectionName"> 
        /// Name of the section to delete. 
        /// </param> 
        /// <exception cref="ArgumentNullException"> 
        /// <paramref name="sectionName"/> is a null reference (Nothing in VB) 
        /// </exception> 
        public void DeleteSection(string sectionName)
        {
            if (sectionName == null)
                throw new ArgumentNullException("sectionName");

            WriteValueInternal(sectionName, null, null);
        }

        #endregion
    }
}

